package day06;

import day05.ArraySort;

import java.util.Arrays;
import java.util.Random;

public class MethodDemo {
    public static void main(String[] args) {
        /*
        say();
        int a = sum(5,6);//sum(5,6)的值就是return后的那个数
        System.out.println(a);//模拟对返回值的后续操作
        int m=5,n=6;
        int b = sum(m,n);//传的是mn里面的数
        System.out.println(b);//模拟对返回值的后续操作
        System.out.println("----------");

        int[] c = generateArray(11,200);
        System.out.println("数组的长度"+c.length);
        for (int i=0;i< c.length;i++){
            System.out.println(c[i]);
        }
        int max = c[0];
        for (int i=1;i<c.length;i++){
            if (c[i]>max){
                max = c[i];
            }
        }
        System.out.println("最大值为"+max);
        System.out.println("+++++++++++++");
        int[] d = generateArray(5,100);
        System.out.println(d[0]);
        System.out.println("排序");
        Arrays.sort(d);
        for (int i=0;i< d.length;i++){
            System.out.println(d[i]);
        }


        System.out.println("你也好");
        sayHi("Tom", 10);
        sayHi("Mary",66);
        System.out.println("-----------");

         */
        //重载overload
        say();//自动绑定无参say
        say("Tom");//自动绑定String参的say
        say("Tom",2);//自动绑定String+int参的say
        //say(3.456);//编译错误,没有double参的say
    }

    //无参无返回值
    public static void say() {
        System.out.println("你好");
    }

    public static void say(String name){
        System.out.println(name);
    }
    public static void say(String name,int age){
        System.out.println(name+","+age);
    }
    public static void say(int age){}//正确的重载
    public static void say(int age,String name){}//正确的重载
    //public static int say(){return 1;}//编译错误,重载与返回值类型无关
    //public static void say(String address){}//编译错误,重载与参数名称无关

    //有参无返回值
    public static void sayHi(String name, int age) {
        if (age>=60){
            return;
        }
        System.out.println("我叫" + name + "我今年" + age + "岁了");
    }
    //有参有返回值
    public static int sum(int num1, int num2){
        int num = num1+num2;
        return num;//返回的是num里面的那个数
        //return num1+num2;//返回的是num1和num2的和
    }
    //生成一个整型数组,并填充数据
    public static int[] generateArray(int len,int max){
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i=0;i< arr.length;i++){
            arr[i] = rand.nextInt(max+1);
        }
        return arr;
    }
}
